package com.fireline.beauty.cashier;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import com.fireline.beauty.jdbc.SqliteJdbcImpl;
import com.zgw.fireline.base.controls.DataTable;
import com.zgw.fireline.base.dataset.Dataset;
import com.zgw.fireline.base.frame.IFunction;
import com.zgw.fireline.base.controls.DataTableColumn;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
 * 积分管理
 * */
public class JfglView implements IFunction {

	private Shell shell;
	/**
	 * @wbp.nonvisual location=27,522
	 */
	private final Dataset jfbdset = new Dataset(
			"select * from jfbd where hybh=?\r\nand (?=0 or (?=1 and decre>0))",
			SqliteJdbcImpl.INSTANCE);
	private Button button;
	private String hybh;

	/**
	 * @wbp.parser.entryPoint
	 */
	@Override
	public Control createControl(Composite parent) {
		this.shell = parent.getShell();
		jfbdset.setKeyColumns(new String[] {});
		Composite content = new Composite(parent, SWT.NONE);
		content.setLayout(new GridLayout(2, false));

		ToolBar toolBar = new ToolBar(content, SWT.FLAT | SWT.RIGHT);

		ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem.setText("增加兑换积分");

		ToolItem tltmNewItem_1 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_1.setText("删除兑换积分");

		button = new Button(content, SWT.CHECK);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setParams();
				jfbdset.update();
			}
		});
		button.setText("只显示兑换记录");

		DataTable dataTable = new DataTable(content, SWT.BORDER
				| SWT.FULL_SELECTION, jfbdset);
		dataTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2,
				1));
		dataTable.setHeaderVisible(true);
		dataTable.setLinesVisible(true);
		
		DataTableColumn dataTableColumn = new DataTableColumn(dataTable, SWT.NONE,"rq");
		dataTableColumn.setText("变动日期");
		dataTableColumn.setWidth(80);
		
		DataTableColumn dataTableColumn_1 = new DataTableColumn(dataTable, SWT.NONE,"lx");
		dataTableColumn_1.setText("变动类型");
		dataTableColumn_1.setWidth(80);
		
		DataTableColumn dataTableColumn_2 = new DataTableColumn(dataTable, SWT.NONE,"incre");
		dataTableColumn_2.setText("积分增加");
		dataTableColumn_2.setWidth(80);
		
		DataTableColumn dataTableColumn_3 = new DataTableColumn(dataTable, SWT.NONE,"decre");
		dataTableColumn_3.setText("积分减少");
		dataTableColumn_3.setWidth(80);
		
		DataTableColumn dataTableColumn_4 = new DataTableColumn(dataTable, SWT.NONE,"syjf");
		dataTableColumn_4.setText("剩余积分");
		dataTableColumn_4.setWidth(80);
		
		DataTableColumn dataTableColumn_5 = new DataTableColumn(dataTable, SWT.NONE,"czy");
		dataTableColumn_5.setText("操作人");
		dataTableColumn_5.setWidth(80);
		
		DataTableColumn dataTableColumn_6 = new DataTableColumn(dataTable, SWT.NONE,"bz");
		dataTableColumn_6.setText("备注");
		dataTableColumn_6.setWidth(80);
		new Label(content, SWT.NONE);
		new Label(content, SWT.NONE);
		setParams();
		return content;
	}

	public void refresh(String hybh) {
		this.hybh = hybh;
		setParams();
		jfbdset.update();
	}

	protected void setParams() {
		jfbdset.setParam(0, hybh);
		jfbdset.setParam(1, button.getSelection());
		jfbdset.setParam(2, button.getSelection());
	}
}
